package com.dspot.declex.override.handler;

import com.dspot.declex.helper.ActionHelper;
import com.dspot.declex.holder.EventHolder;

import org.ohosannotations.OhosAnnotationsEnvironment;
import org.ohosannotations.ElementValidation;
import org.ohosannotations.holder.EBeanHolder;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;

/**
 * ebean处理程序
 *
 * @author Administrator
 * @date 2021/07/27
 */
public class EBeanHandler extends org.ohosannotations.internal.core.handler.EBeanHandler {

    /**
     * ebean处理程序
     *
     * @param environment 环境
     */
    public EBeanHandler(OhosAnnotationsEnvironment environment) {
        super(environment);
    }

    /**
     * 验证
     *
     * @param element 元素
     * @param valid 有效的
     */
    @Override
    public void validate(Element element, ElementValidation valid) {
        if (element.getKind().equals(ElementKind.CLASS)) {
            ActionHelper.getInstance(getEnvironment()).validate(element, this);
        }

        super.validate(element, valid);
    }

    /**
     * 过程
     *
     * @param element 元素
     * @param holder 持有人
     */
    @Override
    public void process(Element element, EBeanHolder holder) {
        super.process(element, holder);

        EventHolder eventHolder = holder.getPluginHolder(new EventHolder(holder));
        eventHolder.setEventRegisteringBlock(holder.getInitBodyBeforeInjectionBlock());
    }

}
